home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7390 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Specifying a Member Function Address For WNDCLASS Structure
  5. Date: 23 Feb 1996 00:04:19 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4gj0a3$gac@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe4.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 22, 1996 05:16:04 in article <Specifying a Member Function Address
  15. For WNDCLASS Structure>, 'yatesc@csee.usf.edu (Randy Yates)' wrote: 
  16.  
  17.  
  18. >Hello, 
  19. >I'm writing a MS-Windows 3.1 program and I'd like to have the 
  20. >message processing procedure for the window class be a member 
  21. >function, but Borland C++ 4.0 complains with a 
  22. >Error GAMECON.CPP 25: Cannot convert 'long (pascal
  23. GameControl::*)(unsigned  
  24. >int,unsigned int,unsigned  
  25. >int,long)' to 'long (pascal *)(unsigned int,unsigned int,unsigned
  26. int,long)' 
  27. You can't -- unless the member function is static.  But, since 
  28. a static member function is functionally more like an ordinary  
  29. procedure than a real member function, IMHO there's not much 
  30. point in it. 
  31.  
  32. Declare your window procedure as an ordinary function, then 
  33. figure out how to compute the object it applies to, and 
  34. then call the appropriate member function.   
  35.  
  36. In some cases, the message or the window can contain the  
  37. object pointer.  One such case is when there's a one-to- 
  38. one correspondence between a window and a class 
  39. instance. 
  40.  
  41. For example: 
  42.  
  43. int CALLBACK MyWndProc (HWND hw, UINT msg, 
  44.                     WPARAM wp, LPARAM lp) 
  45.  { 
  46.     MyClass * p = (MyClass*)::GetWindowLong(hw, .....); 
  47.     p->ProcessMessage(msg, wp, lp); 
  48.  
  49. -- 
  50. Pete Grant 
  51. Kalevi, Inc. 
  52. Software Engineering & development
  53.